<template>
  <div class="app-container">
    <zhezhao :is-show="isShow" />
    <!-- 查询模块 -->
    <div>
      <el-form ref="form" class="form" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select v-model="form.auditStatus" placeholder="请选择" clearable>
                <el-option
                  v-for="item in reviewStatusList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="账户类型">
              <el-select v-model="form.accountType" placeholder="请选择" clearable>
                <el-option
                  v-for="item in accountList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提现银行卡" prop="cardNo">
              <el-select v-model="form.cardNo" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in withdrawalList"
                  :key="index"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提交日期" width="236">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <!--  class="alignRight" -->
          <el-col :span="6" class="alignRight">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <el-button type="primary" @click="handleExport">导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column fixed type="index" label="序号" width="50" align="center" />
        <el-table-column prop="createdAt" label="申请提现日期" align="center" width="180px" />
        <el-table-column prop="amount" label="提现金额" align="center">
          <template slot-scope="scope">
            <span>{{ Number(scope.row.amount).toFixed(2) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updatedAt" label="到账日期" align="center" width="180px" />
        <el-table-column prop="amount" label="到账金额" align="center">
          <template slot-scope="scope">
            <span
              v-if="scope.row.auditStatus == 1"
            >{{ Number(scope.row.amount).toFixed(2) }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column prop="auditStatus" label="提现状态" align="center">
          <template slot-scope="scope">
            <span
              :class="scope.row.auditStatus==2?'col_red':''"
            >{{ scope.row.auditStatus | checkType }}</span>
            <i
              v-if="scope.row.auditStatus == 2"
              class="el-icon-warning"
              @click="handleReason(scope.row.recordId,scope.row.remark)"
            />
          </template>
        </el-table-column>
        <el-table-column prop="accountType" label="账户类型" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.accountType | accountTypeList }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="bankTitle" label="开户行名称" align="center" width="120px" />
        <el-table-column prop="cardNo" label="提现银行卡号" align="center" width="180px" />
        <el-table-column
          prop="accountTitle"
          label="持卡人/企业账户名称"
          align="center"
          width="180px"
        />
        <el-table-column prop="identity" label="身份证号/社会信用代码" align="center" width="180px" />
        <el-table-column prop="phone" label="手机号" align="center" width="120px" />
        <el-table-column label="操作" align="center" fixed="right" width="130px">
          <template slot-scope="scope">
            <el-button
              size="small"
              type="text"
              @click="toRoutes('cashMessageInfo',scope.row.recordId,scope.row.accountType,scope.row.auditStatus)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.pageNum"
            :page-sizes="page_sizes"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import zhezhao from '@/components/CreateMask/index'
import {
  withdrawal,
  cashExport,
  rejeceMsg,
  getBank,
  cardList
} from '@/api/financeListJava'
import commonFn from '@/utils/common'
export default {
  name: 'CashMessage',
  components: { zhezhao },
  filters: {
    // 审核
    checkType(e) {
      switch (e) {
        case 0:
          return '审核中'
          break
        case 1:
          return '审核通过'
          break
        case 2:
          return '驳回'
          break

        default:
          // return "暂无";
          break
      }
    },
    // 账户类型
    accountTypeList(e) {
      switch (e) {
        case 1:
          return '对公'
          break
        case 2:
          return '对私'
          break
        default:
          // return "暂无";
          break
      }
    }
  },
  data() {
    return {
      form: {
        auditStatus: '',
        accountType: '',
        cardNo: '',
        startTime: '',
        endTime: '',
        isPc: 2,
        pageNum: 1,
        pageSize: 10
      },
      // 状态下拉选
      reviewStatusList: [
        { name: '全部', value: '' },
        { name: '待审核', value: '0' },
        { name: '审核通过', value: '1' },
        { name: '审核驳回', value: '2' }
      ],
      accountList: [
        { name: '对公', value: '1' },
        { name: '对私', value: '2' }
      ], // 账户类型
      withdrawalList: [], // 提现银行卡
      dates: null,
      tableLoading: false,
      tableData: [],
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 60, // 总条目数,
      isShow: true
    }
  },
  mounted() {
    this.getSource()
    this.getList(this.form)
    this.handleCardList()
  },
  inject: ['reload'],
  methods: {
    // 路由跳转
    toRoutes(e, id, types, status) {
      const route = {
        name: e,
        query: { id: id, types: types, status: status }
      }
      this.$router.push(route)
    },
    handleCardList() {
      const datas = {
        auditStatus: '1',
        pageNum: 1,
        pageSize: 1000,
        accountType: this.form.accountType
        // accountType: "2"
      }
      // 查询银行卡列表
      cardList(datas)
        .then(res => {
          if (res.data.code == 0) {
            const resData = res.data.data.list
            // this.listData = res.data.data.list;
            const arr = []
            resData.forEach(e => {
              arr.push({
                name: e.cardNo,
                value: e.cardId
              })
            })
            this.withdrawalList = arr
            // if (this.form1.accountType == "1") {
            //     this.withdrawalList = arr;
            // } else {
            //     this.withdrawalList = arr;
            // }
            // arr.unshift({
            //     name: "请选择银行卡",
            //     value: ""
            // });
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: 'warning'
            })
          }
        })
        .catch(err => {
          this.errorStatus(err)
        })
    },
    // 获取提现列表
    getList(e) {
      withdrawal(e)
        .then(res => {
          if (!res.data.code) {
            this.tableData = res.data.data.list
            const arr = []
            this.page_totals = res.data.data.count
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: 'warning'
            })
          }
        })
        .catch(err => {
          this.$message.error(err)
        })
    },

    // 查询
    handleSearch() {
      this.form.pageNum = 1
      if (this.dates != null) {
        if (this.dates.length > 0) {
          this.form.startTime = this.dates[0]
          this.form.endTime = this.dates[1]
        } else {
          this.form.startTime = null
          this.form.endTime = null
        }
      } else {
        this.form.startTime = null
        this.form.endTime = null
      }
      this.getList(this.form)
    },
    // 导出
    handleExport() {
      cashExport(this.form)
        .then(res => {
          commonFn.downFile('商户提现明细', res)
        })
        .catch(err => {
          this.errorStatus(err)
        })
    },

    // 弹窗驳回理由
    handleReason(e, msg) {
      if (!msg) {
        msg = '暂无'
      }
      const datas = {
        id: e,
        remark: msg
      }
      this.$confirm(msg, '驳回理由', {
        showCancelButton: false,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {})
        .catch(() => {})
    },
    // 门店审核
    getSource() {
      const source = sessionStorage.getItem('source')
      const status = sessionStorage.getItem('check_status')
      if (status == 3) {
        this.isShow = false
      } else {
        this.isShow = true
      }
    },
    // 每页显示条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.getList(this.form)
    },
    // 当前页
    handleCurrentChange(val) {
      this.form.pageNum = val
      this.getList(this.form)
    },
    // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      })
    },
    // 成功状态弹窗
    succStatus(txt, status) {
      this.eleMsg(txt, 'success')
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, 'error')
    }
  }
}
</script>
<style scoped>
.alignRight {
    width: 100%;
    text-align: right;
}
.col_red {
    color: red;
}
</style>
